package com.laikan.reader.core.view;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public enum EnumTextType {

    CN(0, "汉字", 24),
    EN(1, "英文", 11),
    NUM(2, "数字", 13),
    SLEFT(3, "居左", 6),
    SRIGHT(4, "居右", 6),
    NORMAL(5, "普通", 24),

    BR(6, "换行", 0),
    IMG(7, "图片", 0),
    WORD(8, "文字", 24),

    NULL(9, "空的", 0);

    int type;
    String info;
    int length;

    EnumTextType(int type, String info, int length) {
        this.type = type;
        this.info = info;
        this.length = length;

    }

	/*public EnumTextType getType(int id){
        switch(id){
			case 1:
				return CN;
			case 2:
				return EN;
			case 3:
				return NUM;
			case 4:
				return SYM_ZH;
			case 5:
				return SYM_EN;
			default:
					return null;
		}
			
	}*/

    /**
     * 这种方式太慢
     *
     * @param str
     *
     * @return
     */
    public static EnumTextType getType(String str) {
        if (str == null) {
            return EnumTextType.NULL;
        }
        Pattern zh = Pattern.compile("[\u4e00-\u9fa5]");
        Pattern num = Pattern.compile("\\d+");
        Pattern en = Pattern.compile("^\\[A-Za-z\\]+$");

        Matcher zh_m = zh.matcher(str);
        Matcher num_m = num.matcher(str);
        Matcher en_m = en.matcher(str);

        if (num_m.matches()) {
            return EnumTextType.NUM;
        }else if (en_m.matches()) {
            return EnumTextType.EN;
        }else if (zh_m.matches()) {
            return EnumTextType.CN;
        }
        return null;

    }

    public int getValue() {
        return type;
    }
}
